package com.whut.whw.base;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;
import com.whut.whw.util.KnifeKit;

import butterknife.Unbinder;

public abstract class BaseActivity extends AppCompatActivity implements ActivityCallback {
    protected Context context;
    // 组合的方式，其中包含一些Activity中常用的公用方法
    protected UiDelegate uiDelegate;
    private Unbinder unbinder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.context = this;

        if (getLayoutId() > 0) {
            setContentView(getLayoutId());
            unbinder = KnifeKit.bind(this);
        }
        // 初始化Logger
        Logger.addLogAdapter(new AndroidLogAdapter());
        initData(savedInstanceState);
        setListener();
    }


    protected UiDelegate getUiDelegate() {
        if (uiDelegate == null) {
            uiDelegate = UiDelegateBase.create(this);
        }
        return uiDelegate;
    }

    @Override
    protected void onStart() {
        super.onStart();
    }


    @Override
    protected void onResume() {
        super.onResume();
        getUiDelegate().resume();
    }


    @Override
    protected void onPause() {
        super.onPause();
        getUiDelegate().pause();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        getUiDelegate().destory();
    }
}
